package com.zcl.javaClassAndObject.exception;

/**
 * @Description:
 * @author: zcl
 * @date: 2021/12/14  11:59
 */

class MyException2 extends Exception {
    public MyException2() {
    }

    public MyException2(String msg) {
        super(msg);
    }

    public MyException2(String msg, int x) {
        super(msg);
        i = x;
    }

    public int val() {
        return i;
    }

    private int i;

}

public class Inheriting2 {
    public static void f() throws MyException2 {
        System.out.println("Throwing MyException2 from f()");
        throw new MyException2();
    }

    public static void g() throws MyException2 {
        System.out.println("Throwing MyException2 from g()");
        throw new MyException2("Originated in g()");
    }

    public static void h() throws MyException2 {
        System.out.println("Throwing MyException2 from h()");
        throw new MyException2("Originated in h()", 47);
    }

    public static void main(String[] args) {
        try {
            f();
        } catch (MyException2 e) {
            e.printStackTrace();
        }
        try {
            g();
        } catch (MyException2 e) {
            e.printStackTrace();
        }
        try {
            h();
        } catch (MyException2 e) {
            e.printStackTrace();
            System.out.println("e.val() = " + e.val());
        }
    }
}
/**
 * Throwing MyException2 from f()
 * Throwing MyException2 from g()
 * Throwing MyException2 from h()
 * e.val() = 47
 * com.zcl.javaClassAndObject.exception.MyException2
 * 	at com.zcl.javaClassAndObject.exception.Inheriting2.f(Inheriting2.java:33)
 * 	at com.zcl.javaClassAndObject.exception.Inheriting2.main(Inheriting2.java:48)
 * com.zcl.javaClassAndObject.exception.MyException2: Originated in g()
 * 	at com.zcl.javaClassAndObject.exception.Inheriting2.g(Inheriting2.java:38)
 * 	at com.zcl.javaClassAndObject.exception.Inheriting2.main(Inheriting2.java:53)
 * com.zcl.javaClassAndObject.exception.MyException2: Originated in h()
 * 	at com.zcl.javaClassAndObject.exception.Inheriting2.h(Inheriting2.java:43)
 * 	at com.zcl.javaClassAndObject.exception.Inheriting2.main(Inheriting2.java:58)
 * */